<?php
class ad extends base{

	public function init(){ // 公用
		parent::init(); // 这是必须的

		$this->tit = '广告';
		$this->modelObj = D('sys_ad');
		$this->cityObj = D('sys_city');
		$this->upload_fileObj = D('upload_file');
		
		// $this->adTypes = array('ershoufang'=>'二手房通栏','zufang'=>'租房通栏');
		$this->adTypes = ['house_esf','house_zf','house_sy','weiqun'];
	}
    
    //列表
	public function index(){
		$this->tabtit = array('全部','禁用');
		$cond = "1=1".$this->cond_city;
		//加入查询条件
		switch($this->tab){
			case '1':
				$cond .=" and status=0";
				break;
			default:
				$cond .=" and status=1";
		}
		$result = $this->modelObj->get_list($cond);
		// dump($result);exit;
		if($result){
			// $this->citys = $this->cityObj->ids($result['list'],'city_id');
			
			$this->list = $result['list'];
			$this->showPage = $result['showPage'];
			$this->total = $result['total'];
		}
		
	}

	//添加
	public function add(){
		if($this->isAjax()){
			$data = $this->postData('data');
			$res = $this->modelObj->add($data);
			$this->renderSuccess('添加成功', "/{$this->routeUrl}/index");
		}
		$this->info = array('sort'=>100,'status'=>1);
		$this->display($this->routeUrl."/set.php");
	}

	//编辑
	public function edit(){
		$id = arg('id');
		if($this->isAjax()){
			$data = $this->postData('data');
			$this->modelObj->edit($id,$data);
			$this->renderSuccess('编辑成功', "/{$this->routeUrl}/index");
		}
		$info = $this->modelObj->get_info($id);
		if($info['img']){
			$info['img'] = $this->upload_fileObj->get_image($info['img']);
		}
		$this->info = $info;
		$this->display($this->routeUrl."/set.php");
	}

    //隐藏
	public function ban(){
		$id = arg('id');
		if($this->isAjax()){
			$res = $this->modelObj->act($id,0);
			$this->renderSuccess('隐藏成功');
		}
	}

	//显示
	public function act(){
		$id = arg('id');
		if($this->isAjax()){
			$res = $this->modelObj->act($id,1);
			$this->renderSuccess('显示成功');
		}
	}

    //删除
	public function del(){
		$id = arg('id');
		if($this->isAjax()){
			$res = $this->modelObj->del($id);
			$this->renderSuccess('删除成功');
		}
	}

}